/*
	Copyright (c) 2013 MeherTJ G. All rights reserved.
	License: LGPL for personnal study or free software.
	*/

#pragma once

#include "zen_macro.h"

#if defined(ZEN_P_LOG_EXCEPTION) || ZEN_OS_ANDROID

#include "zen_log.h"
#define ZEN_LOG_EXCEPTION 1

#endif

#include <typeinfo>
#include <exception>
#include <string>
#include <stdlib.h>

namespace Zen {
	class Exception : public std::exception
	{
	protected:
		char const * m_what;
		char const * m_file;
		int m_line = 0;

	public:
		Exception(char const * whatStr, int no, char const * file, int line) throw()
		: m_what(whatStr)
		, m_file(file)
		, m_line(line)
		{
#if defined(ZEN_LOG_EXCEPTION)
			Zen::LogE("Exception(%s) e:[%d] @%s:%d", whatStr, m_no, file, line);
#endif
		}
		virtual char const * what() const throw() override
		{
			return m_what;
		}
		char const * file() const throw()
		{
			return m_file;
		}
		int line() const throw()
		{
			return m_line;
		}
		int num() { return m_no; }

	protected:
		int m_no= 0;
	};
}

#define must(cond) do \
{ if(!(cond)) throw Zen::Exception("fail", 0, __FILE__,__LINE__); } while(0)

#define musts(cond, str) do \
{ if(!(cond)) throw Zen::Exception(str, 0, __FILE__,__LINE__); } while(0)

#define mustn(cond, str, n) do \
{ if(!(cond)) throw Zen::Exception(str, n, __FILE__,__LINE__); } while(0)

#define throws(str) throw Zen::Exception(str, 0, __FILE__,__LINE__)


